// intercept.js
export const authInterceptor = {
    mounted(el, binding) {
      // 这里可以放置初始化逻辑
  
      // 添加导航拦截器
      uni.addInterceptor('navigateTo', {
        invoke: (e) => {
          console.log('触发拦截器:', e);
          
          const excludeUrl = binding.value || ['/pages/home/home', '/pages/team/team', '/pages/person/person'];
          const index = excludeUrl.findIndex(item => item === e.url); // 检查当前URL是否在不拦截列表中
          const Authorization = uni.getStorageSync("Authorization");
          console.log("Authorization", Authorization);
  
          // 仅当用户未登录且页面不在排除列表时进行拦截
          if (!Authorization && index === -1) {
            uni.switchTab({
              url: "/pages/person/person",
              success: () => {
                uni.showToast({
                  title: '请先登录',
                  icon: 'none'
                });
              }
            });
            // 阻止进一步的跳转操作
            return false;
          }
  
          console.log("跳转前拦截", e);
        }
      });
    },
    unmounted() {
      // 当组件销毁时可以取消拦截器（如果需要）
      uni.removeInterceptor('navigateTo');
    }
  };
  